module.exports = function(grunt) {
    
    var completeSrcPath = function(jsSrcPaths, relPath){
        var srcPaths = [];
        relPath = relPath || '../js/';
        //补全javascript文件路径.
        for(var i=0, len=jsSrcPaths.length; i<len; i++){
            srcPaths[i] = relPath + jsSrcPaths[i];
        }
        return srcPaths;
    };
    
    //--------------------------------------------------------------
    
    //获取UJS子模块的路径提取器.
    var jsGetter = require('./resource_path/js_res.js'),
        jsCorePaths = jsGetter.getResPath(),
        jsMobilePaths = jsGetter.getResPath({
            core : false,
            mobile : true
        }),
        jsMobileNoJQueryPaths = jsGetter.getResPath({
            core : false,
            mobile_noJQuery : true
        }),
        jsAllPaths = jsGetter.getResPath({
            component : true,
            jqueryPlugins : true
        });
        
    //app resource.
        
    var imJsGetter = require('./resource_path/app/im/js_res.js'),
        imJsPaths = imJsGetter.getResPath();
        
    var pageDesignerJsGetter = require('./resource_path/app/pageDesigner/js_res.js'),
        pageDesignerJsPaths = pageDesignerJsGetter.getResPath();
    
    //JS任务配置.
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),        
        concat : {
            dist_mobile : {
                src : completeSrcPath(jsMobilePaths),
                dest : '../build/<%= pkg.name %>.mobile.debug.js'
            },
            dist_mobile_noJQuery : {
                src : completeSrcPath(jsMobileNoJQueryPaths),
                dest : '../build/<%= pkg.name %>.mobile.nojq.debug.js'
            },
            dist_core : {
                src : completeSrcPath(jsCorePaths),
                dest : '../build/<%= pkg.name %>.core.debug.js'
            },
            dist_all : {
                src : completeSrcPath(jsAllPaths),
                dest : '../build/<%= pkg.name %>.debug.js'
            }, 
            
            dist_im : {
                src : completeSrcPath(imJsPaths, '../app/im/js/'),
                dest : '../build/app/im/im.debug.js'
            }, 
            
            dist_pageDesigner : {
                src : completeSrcPath(pageDesignerJsPaths, '../app/pageDesigner/js/'),
                dest : '../build/app/pageDesigner/pageDesigner.debug.js'
            }
        },
        uglify : {
            build_mobile : {
                src : completeSrcPath(jsMobilePaths),
                dest : '../build/<%= pkg.name %>.mobile.min.js'
            },
            build_mobile_noJQuery : {
                src : completeSrcPath(jsMobileNoJQueryPaths),
                dest : '../build/<%= pkg.name %>.mobile.nojq.min.js'
            },
            build_core : {
                src : completeSrcPath(jsCorePaths),
                dest : '../build/<%= pkg.name %>.core.min.js'
            },
            build_all : {
                src : completeSrcPath(jsAllPaths),
                dest : '../build/<%= pkg.name %>.min.js'
            },            
            build_im : {
                src : completeSrcPath(imJsPaths, '../app/im/js/'),
                dest : '../build/app/im/im.min.js',
                beautify : true,
                reserved : true
            },             
            build_pageDesigner : {
                src : completeSrcPath(pageDesignerJsPaths, '../app/pageDesigner/js/'),
                dest : '../build/app/pageDesigner/pageDesigner.min.js',
                beautify : true,
                reserved : true
            }
        }        
    });
        
    require('./../../tools/grunt/node_modules/grunt-contrib-concat/tasks/concat.js')(grunt);    
    require('./../../tools/grunt/node_modules/grunt-contrib-uglify/tasks/uglify.js')(grunt);
    
    // Default task(s).
    grunt.registerTask('default', [ 'uglify', 'concat' ]);
}; 